package com.quad.innovators.salesease.enums;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.quad.innovators.salesease.exception.BusinessException;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;

/**
 * @author : shanshan.li
 * @createTime : 2025/4/8 09:23
 * @Version : 1.0 
 */
@Getter
public enum ScanCodeTypeEnum {

    PACKING_CODE(1, "包装码"),
    IDENTITY_CODE(2, "身份码");

    private final Integer code;
    private final String description;

    ScanCodeTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    static final Map<Integer, ScanCodeTypeEnum> map = new HashMap<>();

    static {
        ScanCodeTypeEnum[] values = values();
        for (ScanCodeTypeEnum scanCodeTypeEnum : values) {
            map.put(scanCodeTypeEnum.code, scanCodeTypeEnum);
        }
    }

    public static ScanCodeTypeEnum useCodeGetEnum(Integer code) {
        ScanCodeTypeEnum scanCodeTypeEnum = map.getOrDefault(code, null);
        if (ObjectUtils.isNull(scanCodeTypeEnum)) {
            throw BusinessException.resultCode(ResultCode.NOT_FOUND);
        }
        return scanCodeTypeEnum;
    }
}
